# deps: Nodejs, gitbook, calibre

# gitbook
# npm install gitbook-cli -g

# calibre
# https://calibre-ebook.com
# sudo apt install calibre

PROJNAME=Front-End-Book
DIST_FOLDER=dist
NODE_VERSION=$(shell cat .nvmrc)
# NVM=. ${NVM_DIR}/nvm.sh && nvm
# NODE=$(NVM) exec ${NODE_VERSION}
# https://github.com/jaegertracing/documentation/pull/48/files
NODE_VER=$(shell node -v)
NODE_MATCH=$(shell if [ $(NODE_VER) = $(NODE_VERSION) ]; then echo true; else echo false; fi)
.PHONY: clean html pdf mobi epub

all: clean html pdf mobi epub

.PHONY: check-node
check-node:
	@echo Build requires Node $(NODE_VERSION), current version $(NODE_VER). && $(NODE_MATCH)

html: check-node _dist_dir
	npx gitbook build . ./${DIST_FOLDER}/html
	rm -f ./${DIST_FOLDER}/html/{TASK.md,Makefile,.editorconfig,.gitignore,.nvmrc,.npmrc}

pdf: check-node _dist_dir
	npx gitbook pdf . ./${DIST_FOLDER}/${PROJNAME}.pdf

epub: check-node _dist_dir
	npx gitbook epub . ./${DIST_FOLDER}/${PROJNAME}.epub

mobi: check-node _dist_dir
	npx gitbook mobi . ./${DIST_FOLDER}/${PROJNAME}.mobi

dev: check-node
	npx gitbook serve

clean:
	rm -rf ${DIST_FOLDER}

_dist_dir:
	mkdir -p ${DIST_FOLDER}
